<?php

class BetChk
{

    public $today;
    public $gametype;
    public $tbl;
    public $tblName;

    public function BetChk($today, $gametype = 1)
    {
        global $g_gametype_3d;
        $this->gametype = $gametype;
        $this->tbl = $g_gametype_3d[$gametype]['en'];
        $this->tblName = $g_gametype_3d[$gametype]['ch'];
        $this->today = $today;
    }

    public function chkBetDate()
    {
        include_once( "class_sb/MyLotto_sb.php" );
        global $conf;
        global $ui;
        $MyLotto_5h = new MyLotto_sb($this->gametype);
        $reVal = false;
        $lotto_data = $MyLotto_5h->getLottosbByDateTime();
        if ($MyLotto_5h->getLottosbByDateTime())
        {
            $reVal = $lotto_data;
        }
        else
        {
            $lotto_data = $MyLotto_5h->getLottoNextDateTime();
            if ($lotto_data)
            {
                $script = " <script>"
                        . "           //setTimeout('location.reload()', 9000);\n"
                        . "           var CountDownSecond = {$lotto_data['sec']};\n"
                        . "           CountDown();\n"
                        . "           function CountDown() {\n"
                        . "               if (CountDownSecond != 0) {\n"
                        . "                   CountDownSecond -= 1;\n"
                        . "                   document.getElementById('cut_time').innerHTML = '目前暂无{$this->tblName}可下注期数！！距离下一期开盘还有' + CountDownSecond + '秒';\n"
                        . "               }\n"
                        . "               else\n"
                        . "               {\n"
                        . "                   parent.mainFrame.location.reload();\n"
                        . "                   parent.leftFrame.location.reload();\n"
                        . "                   return;\n"
                        . "               }\n"
                        . "               setTimeout('CountDown()', 1000);\n"
                        . "           }\n"
                        . "   </script>\n"
                        . "";
                unset($lotto_data);
                $ui->showErrorPage($script, true);
            }
            else
            {
                $s=$conf->get("startbet_".$this->tbl);
				$startdate=date('Y-m-d H:i:s');
				$enddate=(date('H')<=10?date('Y-m-d'):date('Y-m-d',strtotime('1 day'))).' '.substr($s,0,2).':'.substr($s,2,2).':00';
				$r=timediff(strtotime($startdate),strtotime($enddate));
				$ui->showErrorPage("<div class='time2'><div class='timeDiv'>".sprintf('%02d',$r['hour']).":".sprintf('%02d',$r['min']).":".sprintf('%02d',$r['sec'])."</div></div>");
            }
            $reVal = false;
        }
        unset($lotto_data);
        return $reVal;
    }

}
function timediff($begin_time,$end_time) 
{ 
      if($begin_time < $end_time){ 
         $starttime = $begin_time; 
         $endtime = $end_time; 
      } 
      else{ 
         $starttime = $end_time; 
         $endtime = $begin_time; 
      } 
      $timediff = $endtime-$starttime; 
      $days = intval($timediff/86400); 
      $remain = $timediff%86400; 
      $hours = intval($remain/3600); 
      $remain = $remain%3600; 
      $mins = intval($remain/60); 
      $secs = $remain%60; 
      $res = array("day" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs); 
      return $res; 
}
?>